/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"59A5E876-D95F-4255-88B0-BE0E3DDA30F2",variableType:4}
 */
var esta_en_totalizar = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C11F361E-DB3E-4F64-A79F-35FD95240FD9",variableType:4}
 */
var zconf_hist_egre_cliente = 2;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"667CF16D-815C-454E-BEE0-19151FB232F4",variableType:93}
 */
var gFechaHasta_costo_hist = null;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"6B814985-9CFD-4722-986D-92CEA066A646",variableType:93}
 */
var gFechaDesde_costo_hist = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3B6B6FB2-4987-4641-8B55-21E5712252D3",variableType:8}
 */
var zconf_tipo_prod_terminado = 4;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"DB46EB2A-168B-48E5-8343-2EDEE18A67C0"}
 */
var gprecision_formato_cant_comp = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"211998A9-7AA0-403F-9F8D-8050E8DF8D72"}
 */
var gprecision_formato_cant = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"1599827C-658F-494A-9DC3-275A892CE32A"}
 */
var gprecision_formato_costo = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"229EB9AD-A407-4530-AD55-F5777046CD50"}
 */
var gTitulo_despiece_tree_1 = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"791E6BA4-0A59-427F-86E4-B6BBDB85512C",variableType:4}
 */
var gprecision_dec_costo = 12;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C06FC37F-BC2F-4D30-BC1C-4D5315CE92B9",variableType:4}
 */
var gprecision_dec_cant_comp = 12;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4D5A3687-F10F-43A2-8254-9F2E4DB62A60",variableType:4}
 */
var gprecision_dec_cant = 12;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"187FBFBD-03BD-48A6-ADE5-429C68C753B6"}
 */
var nuevo_producto_descr = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"2E6B7C25-235D-4618-88A3-051061767D42"}
 */
var nuevo_producto = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"38AB1C14-8D73-409C-A337-85F9DF0363BE",variableType:4}
 */
var gnuevo_producto_id = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"989FC7A2-2A56-4838-9A1A-04F64FED91E3",variableType:4}
 */
var zparam_costos_gral_tipo_subtot = 3;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"F18690D6-81EF-4157-8DEA-2B5058CCBBA2",variableType:4}
 */
var zparam_costos_gral_tipo_acum = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"93565E8C-4A87-4844-8D74-EA797FFEC2E8",variableType:4}
 */
var zparam_costos_gral_tipo_arbol = 1;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"B84F96CA-3ED8-4EAA-AB2F-95D08D90DF1C"}
 */
var gTitulo_despiece_tree = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"744FDA1C-765C-40ED-A7B8-F1EDD56176AD",variableType:4}
 */
var zconf_tipo_prod_centro_costo = 5;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"F7ABB574-58EE-42CE-BEE3-7F12E844116D",variableType:93}
 */
var gFechaDesde_resumen = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EA13BB0A-0DB3-4A5F-88D0-7DF72A7F2DF3",variableType:4}
 */
var gTipo_iva_emisor = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"79F44370-3E6E-4F0A-B743-ABE89393CF01",variableType:8}
 */
var gPorc_iva_emisor = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"A2260D00-7474-4209-824F-55EB686FDEE4",variableType:4}
 */
var guserv_id = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D5008F55-CEA5-4BF8-9E56-B94DC61B4288",variableType:4}
 */
var gSucursal = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B24CCEBF-21C2-408A-9498-660B25E4B2A9",variableType:4}
 */
var gproveedor_o_fletero = 0;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"013111DB-86DE-4E0E-9D21-1EB5855B525A",variableType:4}
 */
var zparm_costos_tipo_detalle_valor = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FB4E5DF5-9D4E-4B11-B984-76421E7CBCB2",variableType:4}
 */
var zparm_costos_tipo_detalle_cantidad = 1;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"BD042C9C-4660-48B8-8E6A-FE4C91485F03"}
 */
var gCharNull = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"EA5E90AF-6F97-495C-AD7B-32D21B6D8265"}
 */
var gCharConcat = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1385AC90-DD39-4EC8-8D0A-83DF128D1689",variableType:4}
 */
var gProveedorPrecio = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"21F627E2-47A9-44FF-9203-9B2E0DFACCD9",variableType:4}
 */
var zparam_cond_iva_default = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"4C9DB464-6782-42B0-A5F2-753FB2689F5D",variableType:4}
 */
var gClienteDesde = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"594A6B0B-7B56-452F-8D35-CC60265F2B91",variableType:4}
 */
var zconf_tipo_remito_interno = 03;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"83CBD5AE-980F-4186-9C56-67A980D7ADB2"}
 */
var gCod_producto = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"AB263C45-5176-4DE9-97FA-E995D956E8E3",variableType:8}
 */
var gIva_factura = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"172F1697-D340-48A7-9F82-4B3C0FA3961A",variableType:4}
 */
var zparam_codigo_recepciones = 62;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"E012C5B5-BAC1-4A30-BF6C-A5F00B9A40B0",variableType:4}
 */
var zconf_tipo_minorista = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"821CCAFE-8938-4341-B296-F5150CC1C75D",variableType:4}
 */
var zconf_tipo_mayorista = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"024D7700-9714-45B3-9043-407115C00BA2",variableType:4}
 */
var zparam_deposito_default = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7D88D36B-7DAF-4D55-AB54-38459A7D3C20",variableType:4}
 */
var gCliente = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"42E6792E-911D-46B1-9E57-1FD717056C03",variableType:4}
 */
var zconf_rem_ingresado = 1;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"B4F2D121-3BF1-44B1-B0F8-F6D45AB40BC5"}
 */
var zconf_path_pdf = 'c:/resumenes_pdf';

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"BF7CE268-9984-4B36-A856-34DB2CA14433",variableType:4}
 */
var gProveedorRecep = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"7CF73889-0801-4769-B8BE-492C9151B0EA",variableType:4}
 */
var gProveedorOC = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"1699596E-CDF0-437D-B517-49815925CDCF",variableType:4}
 */
var zparam_codigo_ocompra = 61;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"6CC06CFA-207E-409D-B862-EBCE832FB9C5"}
 */
var zconf_letra_remito = "X";

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"23266B03-0C4B-476C-88FF-3A164F2C0E0D",variableType:4}
 */
var zconf_hist_ingre_interno = 3;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"498FE8E1-006E-4D43-A685-F21E5D9393C2",variableType:4}
 */
var zconf_numeracion_remito_propio = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"BDD44EA1-AA14-419B-BC5B-A6398BCF45EB",variableType:4}
 */
var zconf_numeracion_recep = 6;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"280A078F-3914-4C54-832C-C5F129E23C70",variableType:4}
 */
var zconf_numeracion_remito_int = 3;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"0234AD96-52A8-4E4E-A8AB-74B5A4548D48",variableType:4}
 */
var zparam_moneda_default = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3B35B10E-4B4E-4D8F-8824-34D4CB474E42",variableType:4}
 */
var zconf_hist_egre_interno = 4;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9D1A2DA6-F09E-46E7-B9FC-5C6FD790C203",variableType:4}
 */
var gProductoPrecio = null;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"2DF44BE5-952F-4B2F-B303-F811405C0C88",variableType:93}
 */
var gFechaHasta = null;

/**
 * @type {Date}
 *
 * @properties={typeid:35,uuid:"D499A2DF-3AE1-4A64-B542-474CD9DBC7BD",variableType:93}
 */
var gFechaDesde = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"B1837186-2CF5-484B-87D7-BD91F60A5217"}
 */
var gMensaje = null;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"D53F0630-BE32-41AE-9619-EACD3FCBE2A1",variableType:4}
 */
var zparam_planes_dias_atras = 90;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"352A8A41-BDC7-4577-8640-5D0BD51B5BE2",variableType:4}
 */
var zconf_hist_fabricacion = 5;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"F1B9A531-3640-4A1E-8C32-F05474B32407"}
 */
var zconf_letra_ordenes = "X";

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3BB4F788-A773-499D-B844-2CC10CD8B020",variableType:4}
 */
var gsucursal_default_ind = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"482A3775-D000-4ADB-AD10-58E89C94AB7D",variableType:4}
 */
var zconf_ordfab_cumplida_parc = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"C330D980-2C3E-4DAE-9E43-5E766711A871",variableType:4}
 */
var zconf_ordfab_cumplida = 3;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"095084CE-19E4-4624-A35D-8644F820CE02",variableType:4}
 */
var zconf_ordfab_anulada = 4;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"B414F3BC-FFB8-4226-B708-AFF9582702E5",variableType:4}
 */
var zconf_ordfab_ingresada = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"9ACAF0AB-51C8-41EA-9E40-F233CE3F3100",variableType:4}
 */
var zparam_fabric_seccion_default = 2;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"EC45907D-B4A4-4DF8-A451-82C81AD3423B",variableType:4}
 */
var zconf_numeracion_parfab = 5;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"3573442B-1970-418C-A9CE-2DD7D970F64B",variableType:4}
 */
var zconf_numeracion_ordfab = 4;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"14408C90-41AB-442C-9D8B-8DEA974E87F1",variableType:4}
 */
var gdeposito_default = 1;

/**
 * @type {Number}
 *
 * @properties={typeid:35,uuid:"FF1B394A-0B83-4BB6-B324-D2B6472FCB48",variableType:4}
 */
var gdeposito_ind = null;

/**
 * @properties={typeid:24,uuid:"B909E05E-B57F-4248-AAFA-7547DC6C0B5E"}
 */
function gMensajes() 
{
	globals.DIALOGS.showWarningDialogs ('Aviso',globals.gMensaje,'OK')
}

/**
 * @properties={typeid:24,uuid:"DA482723-359D-42FF-951A-7A0B6A8CC8FB"}
 */
function configuraCharConcat() 
{
	//Caracter para concatenar campos en los querys
	if (databaseManager.getDatabaseProductName('infocom') == 'postgresql')
	{
		globals.gCharConcat = '||'
		globals.gCharNull	= 'COALESCE'
	}
	else
	{
		globals.gCharConcat = '+'
		globals.gCharNull	= 'isnull'
	}

}

/**
 * Called when the valuelist needs data, it has 3 modes.
 * real and display params both null: return the whole list
 * only display is specified, called by a typeahead, return a filtered list
 * only real value is specified, called when the list doesnt contain the real value for the give record value, this will insert this value into the existing list
 *
 * @param {String} displayValue The value of a lookupfield that a user types
 * @param realValue The real value for a lookupfield where a display value should be get for
 * @param {JSRecord} record The current record for the valuelist.
 * @param {String} valueListName The valuelist name that triggers the method. (This is the FindRecord in find mode, which is like JSRecord has all the columns/dataproviders, but doesn't have its methods)
 * @param {Boolean} findMode True if foundset of this record is in find mode
 *
 * @returns {JSDataSet} A dataset with 1 or 2 columns display[,real]
 *
 * @properties={typeid:24,uuid:"C10F44FC-2A51-4EFB-8E05-D8124C89D51B"}
 */
function getDataSetForValueListClientesMet(displayValue, realValue, record, valueListName, findMode) 
{
	var servidor = 'infocom'
	
	if (displayValue == null && realValue == null) 
	{
	 return databaseManager.getDataSetByQuery(servidor, "select razon_social, cliente_id from clientes order by razon_social", null, 100);
	}
	else if (displayValue != null) 
	{
  		var args = ["%"+displayValue + "%", "%"+displayValue + "%"]
  		return databaseManager.getDataSetByQuery(servidor, "select razon_social, cliente_id from clientes where CAST(cliente_id AS Varchar) ilike ? or razon_social ilike ?  order by razon_social", args, 100);
  	}
  	else if (realValue!=null)
  	{
  		var args = [realValue]
  		return databaseManager.getDataSetByQuery(servidor, "select razon_social, cliente_id from clientes where cliente_id = ?  order by razon_social", args, 100);
  	}
	return null
}

/**
 * Called when the valuelist needs data, it has 3 modes.
 * real and display params both null: return the whole list
 * only display is specified, called by a typeahead, return a filtered list
 * only real value is specified, called when the list doesnt contain the real value for the give record value, this will insert this value into the existing list
 *
 * @param {String} displayValue The value of a lookupfield that a user types
 * @param realValue The real value for a lookupfield where a display value should be get for
 * @param {JSRecord} record The current record for the valuelist.
 * @param {String} valueListName The valuelist name that triggers the method. (This is the FindRecord in find mode, which is like JSRecord has all the columns/dataproviders, but doesn't have its methods)
 *
 * @returns {JSDataSet} A dataset with 1 or 2 columns display[,real]
 *
 * @properties={typeid:24,uuid:"02DCFCCA-C521-44EB-8CEC-A26763A35CA8"}
 */
function getDataSetForValueListProductosMet(displayValue, realValue, record, valueListName) 
{
	var servidor = 'infocom'
	
	if (displayValue == null && realValue == null) {
		return databaseManager.getDataSetByQuery(servidor, "select cod_producto "+globals.gCharConcat+" ' - ' "+globals.gCharConcat+" descripcion, producto_id from productos where inactivo = 0 order by cod_producto", null, 100);
	} else if (displayValue != null) {
		// TYPE_AHEAD filter call, return a filtered list
		var args = ["%"+displayValue + "%", "%"+displayValue + "%"]
		return databaseManager.getDataSetByQuery(servidor, "select cod_producto "+globals.gCharConcat+" ' - ' "+globals.gCharConcat+" descripcion,producto_id from productos where upper(cod_producto) like upper(?) or upper(descripcion) like upper(?) and inactivo = 0 order by cod_producto", args, 100);
	}
	else if (realValue!=null)
	{
		var args = [realValue]
		return databaseManager.getDataSetByQuery(servidor, "select cod_producto "+globals.gCharConcat+" ' - ' "+globals.gCharConcat+" descripcion, producto_id from productos where producto_id = ? and inactivo = 0", args, 100);
	}
	return null
}

/**
 * Called when the valuelist needs data, it has 3 modes.
 * real and display params both null: return the whole list
 * only display is specified, called by a typeahead, return a filtered list
 * only real value is specified, called when the list doesnt contain the real value for the give record value, this will insert this value into the existing list
 *
 * @param {String} displayValue The value of a lookupfield that a user types
 * @param realValue The real value for a lookupfield where a display value should be get for
 * @param {JSRecord} record The current record for the valuelist.
 * @param {String} valueListName The valuelist name that triggers the method. (This is the FindRecord in find mode, which is like JSRecord has all the columns/dataproviders, but doesn't have its methods)
 * @param {Boolean} findMode True if foundset of this record is in find mode
 *
 * @returns {JSDataSet} A dataset with 1 or 2 columns display[,real]
 *
 * @properties={typeid:24,uuid:"2F7C158B-ADD3-42C7-88F2-8BD0563BB6DC"}
 */
function proveedor_consulta_getDataSetForValueList(displayValue, realValue, record, valueListName, findMode) 
{
	if (displayValue == null && realValue == null) 
	{
		if (globals.gproveedor_o_fletero==1)
			return databaseManager.getDataSetByQuery("infocom", "select razon_social, proveedor_id, es_fletero from proveedor where razon_social <> NULL and razon_social <> ' ' and es_fletero=1 order by razon_social asc", null, -1);
		else
			return databaseManager.getDataSetByQuery("infocom", "select razon_social, proveedor_id, es_fletero from proveedor where razon_social <> NULL and razon_social <> ' ' order by razon_social asc", null, -1);
	}
	else 
		if (displayValue != null)    
		{
		
		var args = [displayValue + "%", displayValue + "%"]
		if (globals.gproveedor_o_fletero==1)
			return databaseManager.getDataSetByQuery("infocom", "select razon_social, proveedor_id from proveedor where razon_social like ? and es_fletero=1", args, -1);
		else
			return databaseManager.getDataSetByQuery("infocom", "select razon_social, proveedor_id from proveedor where razon_social like ? ", args, -1);
		}
		else 
			if (realValue != null) 
			{
			var args = [realValue];
			return databaseManager.getDataSetByQuery("infocom", "select razon_social, proveedor_id from proveedor where proveedor_id = ?", args, 1);
			}
	return null
}

/**
 * @properties={typeid:24,uuid:"4564A657-2817-4CDD-9C34-8B75F9746E9E"}
 */
function clienteActivo(cliente_id) 
{

	var $query = 'select cliente_id from clientes where cliente_id = ? and inactivo = ?'
	var $args = [cliente_id, 0]             
	var $ds = databaseManager.getDataSetByQuery('infocom',$query,$args,1)
	
	return $ds.getMaxRowIndex()
}

/**
 * @properties={typeid:24,uuid:"03830EF8-7D63-4AF7-894C-BB4835DD47BB"}
 */
function calculaBonificacion(texto) 
{
	var bonificacion
	if (texto != '' && texto != null)
	{
		var i 	= 0
		var tot = 100
		
		while (texto.indexOf('+', i) > 0)
		{
			var j = texto.indexOf('+', i)
			var nro = texto.slice(i, j) *1
			i = j+1
			tot = tot * (100 - nro) / 100
		}
		var nro = texto.slice(i, texto.length)*1
		tot = tot * (100 - nro) / 100
		bonificacion = 100 - tot
	}
	else
		bonificacion = 0
		
	return bonificacion
}

/**
 * @properties={typeid:24,uuid:"29F39C82-2FA6-4931-A6AD-B26333BE9FEA"}
 */
function gOnHide(event) {
	if (forms[event.getFormName()].es_preview == undefined || forms[event.getFormName()].es_preview == 0)
	{
		var resp = globals.DIALOGS.showQuestionDialog( 'Confirma',  '¿Seguro que desea salir?' ,  'Si', 'No')
		if (resp == 'Si')
		{
		    databaseManager.revertEditedRecords()
		    databaseManager.setAutoSave(true)
		    return true   //  onHide con respuesta "No" - evita cabeceras vacías
		}
		else
		{
		    return false // onHide con respuesta "No" - evita cabeceras vacías
		}
	}
	return true
}

/**
 * 
 * @param {JSRecord} $rcd
 * @param {JSRecord} [$prod]
 * @param {Number}  [$tipo]
 * 
 * @properties={typeid:24,uuid:"E22385E4-157E-46B3-90E9-4CD93797CD13"}
 */
function defineUnidad($rcd, $prod, $tipo) {
	//Si no es madera, la unidad es 1
	$rcd.unidad = 1
	// Calculo de la cantidad alternativa
	$rcd.cantidad_alter = calculoCantAlt($rcd)
}

/**
 * @properties={typeid:24,uuid:"2D8BA8E0-E53D-439F-B605-4DEE1920DD64"}
 */
function calculoCantAlt($rcd) 
{
	if ($rcd.unidad == 1)
    	return $rcd.cantidad;
	else 
		if ($rcd.unidad == 2)
	    	return $rcd.metro_cuadrado;
		else
			if ($rcd.unidad == 4)
	    		return $rcd.pie_cuadrado;
			else
				return 0
}

/**
 * @properties={typeid:24,uuid:"A55E3AC0-EB4F-414A-B8AE-C07AD986F5BA"}
 */
function calcula_cuit(cuit) 
{
// TODO    19/01/2011 verificar que func . tomado de clientes_alta
	
	/*  
	VERIFICACION DE CUIT/CUIL (genérico) 
    El CUIL consta de 11 números. Los 10 primeros (2 + 8) constituyen el código de identificación y el último, el dígito de verificación.
	* Para obtener esta verificación se procede de la siguiente forma: A cada dígito del código, se lo multiplica por los siguientes números (respectivamente) 5, 4, 3, 2, 7, 6, 5, 4, 3, 2 
	* y cada valor obtenido, se suma para obtener una expresión (que llamaremos "valor 1". A este "valor 1", 
	* se le saca el resto de la división entera a 11. 
	* Se obtiene de esta forma un número (del 0 al 10) (que llamamos "valor 2").
	* Sacamos la diferencia entre 11 y el "valor 2", y obtenemos un valor comprendido entre 1 y 11 (llamémosle "valor 3"). 
	* Si "valor 3"=11, el código verificador es cero. Si "valor 3"=10, el código verificador es 9. 
	* En cualquier otro caso, el código verificador es "valor 3". 
* Ejemplo numérico con un número de CUIT, que es 20-17254359-7.
2 0 1 7 2 5 4 3 5 9
x
5 4 3 2 7 6 5 4 3 2
------------------------------------------------
10 + 00 + 03 + 14 + 14 + 30 + 20 + 12 + 15 + 18 = 136 v1 = 136 136 mod 11 = 4 v2 = 4 11 - 4 = 7 v3 = 7 => Código de verificación es siete. 

 */
	// CALCULO DE DIGITO VERIFICADOR del CUIT 
	var multi=new Array(5,4,3,2,7,6,5,4,3,2); // numeros por los que hay que multiplicar c/u
	var uno=0;
	var vector=new Array(cuit[0],cuit[1],cuit[3],cuit[4],cuit[5],cuit[6],cuit[7],cuit[8],cuit[9],cuit[10]);
	// SUMA de cada numero multiplicado por 5432765432 cada uno respectivamente
	for (var i = 0; i < 10; i++) // recorre hasta el digito verificador
	{
		vector[i]=vector[i] * multi[i]; // cada numero por 5432765432 cada uno respectivamente
		uno=uno + vector[i];
	}
	// DIVIDIR suma de produtos / 11 y obtener el resto
	
	// RESTO
	var resto = uno % 11;  
	
	// DIGITO = 11 - RESTO  
	var digito = 11 - resto; // para todos los demas la diferencia es el digito
	
	if (digito==10)
		digito=9; // si resto = 10 => fuerza  digito = 9
	
	// COMPARA con lo ingresado
	if (cuit[12]!=digito)	
		return false;
	else
		return true;
	
}

/**
 * @properties={typeid:24,uuid:"73D3FA71-D390-47B8-8F2A-6FFA7D8C3AEC"}
 */
function duplicacion_oc_cabecera_ind(letra,sucursal,nro_aux,codigo_movimiento) 
{
	var maxReturnedRows = 10;
	var query = 'select letra,sucursal,nro_oc from oc_cabecera where letra = ? and sucursal = ? and nro_oc = ?';
	var args = new Array();
	args[0] = letra
	args[1] = sucursal
	args[2] = nro_aux
	var dataset = databaseManager.getDataSetByQuery('infocom', query, args, maxReturnedRows);
	return dataset.getMaxRowIndex() // si es cero, no existe
}
/**
 * @properties={typeid:24,uuid:"C5E065D9-9E6A-457B-8913-BE8EDF1AB644"}
 */
function armar_formato_numero($decimales) 
{
	var formato_dec = null
	
	if ($decimales == 0) 
		return '###,###,##0'
		
	for( var i = 1 ; i <= $decimales ; i ++)    
	{
		formato_dec = formato_dec + '#'
	}
	return '###,###,##0' + '.' + formato_dec  


}

/**
 * @properties={typeid:24,uuid:"D4824AD5-5438-4400-908F-3AF37F312138"}
 */
function armar_numero_alineado($numero,$decimales,$formato) 
{
	var aux_relleno_ent = '         '  // 9 
	var aux_relleno_dec = '            '  // 12
	var aux_importe = null
	//var formato_ent = '###,###,##0'
	//var formato_dec = null
	//var aux_entero  = 000000000
	//var aux_decimal = 000000000

	// numero recibido	
		//aux_importe = utils.numberFormat($numero,'###,###,##0.############')   // max. long. 9 ent, 12 dec.
		aux_importe = utils.numberFormat($numero,$formato)       // $formato armado con metodo armar_formato_numero()
		var pos = utils.stringPosition(aux_importe, '.', 1, 1)   // posicion del punto
	
		
		if(pos > 0)  // tiene decimales
		
			var uno = utils.stringLeft(aux_importe, pos - 1)
		else
			var uno = aux_importe
	
		var aux_longi = 9 - uno.length 
		var entero_armado = aux_relleno_ent.substr(1,aux_longi) + uno
		
		// decimales

		if(pos > 0)  // tiene decimales
		{
			if(pos > $decimales)   //houston  tenemos un problema
				return false		
			/* 
			for( var i = 1 ; i <= $decimales ; i ++)    
			{
				formato_dec = formato_dec + '#'
			}  */
			var dos = utils.stringMiddle(aux_importe,pos + 1,$decimales) 
			var aux_long = $decimales
		}
		else	
		{
			//formato_dec = '############'
			var dos = 0
			var aux_long = 12
		}
		var decimal_armado = dos + aux_relleno_dec.substr($decimales + 1,aux_long)

		// var formato = '###,###,##0' + '.' + formato_dec 
		//return formato
		return entero_armado + '.' + decimal_armado
}
